package com.soft.mainsite.module.sensitiveword.web;

import com.soft.mainsite.module.sensitiveword.dto.SensitiveWordQueryParams;
import com.soft.mainsite.module.sensitiveword.service.SensitiveWordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * SensitiveWordController.java 此类用于敏感词控制层
 *
 * @author:李昭阳
 * @date:2019/4/10 0010
 * @remark:
 */
@Controller
@RequestMapping("/sensitiveWord")
public class SensitiveWordController {

    @Autowired
    private SensitiveWordService sensitiveWordService;

    /**
     * 分页条件查询敏感词
     * @param queryParams
     * @param model
     * @return
     */
    @RequiresPermissions("sensitiveWord:admin")
    @RequestMapping("/list")
    public String list(SensitiveWordQueryParams queryParams, Model model) {
        // 使用中的敏感词
        queryParams.setWordStatus(1);
        model.addAttribute("useWord", sensitiveWordService.getSensitiveWordByConditions(queryParams));
        model.addAttribute("pojo", queryParams);
        return "sensitiveWord/word_list";
    }

    /**
     * 批量添加敏感词列表
     * @param request
     * @return
     */
    @RequiresPermissions("sensitiveWord:save")
    @ResponseBody
    @RequestMapping("/save")
    public String save(HttpServletRequest request) {
        String[] wordContents = request.getParameterValues("wordContent");
        return sensitiveWordService.save(wordContents);
    }

    /**
     * 删除敏感词
     * @param ids
     * @return
     */
    @RequiresPermissions("sensitiveWord:delete")
    @ResponseBody
    @RequestMapping("/delete")
    public String delete(@RequestParam(value = "deleteIds",required = false) Long[] ids) {
        return sensitiveWordService.delete(ids);
    }
}
